package two_pointer.lc_lcp_28;

import java.util.Arrays;

public class Solution {
    public int purchasePlans(int[] nums, int target) {
        int mod = (int)1e9 + 7;
        Arrays.sort(nums);
        int res = 0;
        int j = nums.length - 1;
        for (int i = 0; i < j; i++) {
            while (i < j && nums[i] + nums[j] > target) {
                j--;
            }
            if (i < j && nums[i] + nums[j] <= target) {
                res += j - i;
                res = res % mod;
            }
        }
        return res % mod;
    }
}
